/*
 * SetTokenCountDialogCommand.java
 *
 * Created on 7 czerwiec 2007, 13:58
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package edu.uj.petri.commands;

import edu.uj.petri.document.Document;
import edu.uj.petri.model.Place;
import java.util.ResourceBundle;
import javax.swing.JOptionPane;

/**
 *
 * @author Paweł
 */
public class SetTokenCountDialogCommand extends Command{
    
    private Place place;
    
    /** Creates a new instance of SetTokenCountDialogCommand */
    public SetTokenCountDialogCommand( Place place ){
        super(true); // do not remember on command stack
        this.place = place;
    }

    public String toString() {
        
        return ""; // executeAndForget
    }

    void execute() {
        
        String newCount = JOptionPane.showInputDialog( null, ResourceBundle.getBundle("edu/uj/petri/messages").getString("zmiana_liczby_tokenow_prompt"), place.getTokens());
        
        if (newCount != null && !newCount.equals(""))
        {
            try 
            {
                Document.getActiveDocument().execute(new AddRemoveTokensCommand( place, Integer.parseInt(newCount) ));
            }
            catch (NumberFormatException e)
            {
                JOptionPane.showInputDialog( this, ResourceBundle.getBundle("edu/uj/petri/messages").getString("to_nie_jest_liczba"));
            }
          
        }
    }

    void undo() {
    }

    boolean canBeCombined(Command c) {
        return false;
    }

    private static final long serialVersionUID = 7555683864683567L;
}
